package com.ruoyi.evaluate.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ruoyi.evaluate.mapper.EvaluateResultsMapper;
import com.ruoyi.base.domain.BaseStudent;
import com.ruoyi.evaluate.domain.EvaluateResults;
import com.ruoyi.evaluate.service.IEvaluateResultsService;
import com.ruoyi.system.service.ISysConfigService;

/**
 * 评价结果Service业务层处理
 * 
 * @author yepanpan
 * @date 2020-11-09
 */
@Service
public class EvaluateResultsServiceImpl implements IEvaluateResultsService 
{
    @Autowired
    private EvaluateResultsMapper evaluateResultsMapper;
    @Autowired
    private ISysConfigService sysConfigService;


    /**
     * 查询未评价学生
     * 
     * @param semId 学期
     * @return 评价结果集合
     */
    @Override
    public List<BaseStudent> selectUnEvaluateStudent(Long semId){
    	return evaluateResultsMapper.selectUnEvaluateStudent(semId);
    }
    
    /**
     * 查询评价结果
     * 
     * @param id 评价结果ID
     * @return 评价结果
     */
    @Override
    public EvaluateResults selectEvaluateResultsById(Long id)
    {
        return evaluateResultsMapper.selectEvaluateResultsById(id);
    }
    
    /**
     * 查询评价结果列表
     * 
     * @param evaluateResults 评价结果
     * @return 评价结果
     */
    @Override
    public List<EvaluateResults> selectEvaluateList(EvaluateResults evaluateResults)
    {
    	List<EvaluateResults> list =  evaluateResultsMapper.selectEvaluateResultsList(evaluateResults);
    	if((list == null || list.size() == 0) && evaluateResults.getSemId() != null && evaluateResults.getClassId() != null) {
    		evaluateResultsMapper.genStudents(evaluateResults);
    		list =  evaluateResultsMapper.selectEvaluateResultsList(evaluateResults);
    	}
    	return list;
    }

    /**
     * 查询评价结果列表
     * 
     * @param evaluateResults 评价结果
     * @return 评价结果
     */
    @Override
    public List<EvaluateResults> selectEvaluateResultsList(EvaluateResults evaluateResults)
    {
    	List<EvaluateResults> list =  evaluateResultsMapper.selectEvaluateResultsList(evaluateResults);
    	return list;
    }

    /**
     * 新增评价结果
     * 
     * @param evaluateResults 评价结果
     * @return 结果
     */
    @Override
    public int insertEvaluateResults(EvaluateResults evaluateResults)
    {
        return evaluateResultsMapper.insertEvaluateResults(evaluateResults);
    }

    /**
     * 修改评价结果
     * 
     * @param evaluateResults 评价结果
     * @return 结果
     */
    @Override
    public int updateEvaluateResults(EvaluateResults evaluateResults)
    {
        return evaluateResultsMapper.updateEvaluateResults(evaluateResults);
    }

    /**
     * 批量删除评价结果
     * 
     * @param ids 需要删除的评价结果ID
     * @return 结果
     */
    @Override
    public int deleteEvaluateResultsByIds(Long[] ids)
    {
        return evaluateResultsMapper.deleteEvaluateResultsByIds(ids);
    }

    /**
     * 删除评价结果信息
     * 
     * @param id 评价结果ID
     * @return 结果
     */
    @Override
    public int deleteEvaluateResultsById(Long id)
    {
        return evaluateResultsMapper.deleteEvaluateResultsById(id);
    }
    
    @Override
    @Transactional
    public int countEvaluateResults(Long semId) {
    	evaluateResultsMapper.countQuantifyResults(semId);
    	Float qs = Float.valueOf(sysConfigService.selectConfigByKey("quantify.scale"));
    	Float es = Float.valueOf(sysConfigService.selectConfigByKey("evaluate.scale"));
    	return evaluateResultsMapper.countEvaluateResults(semId, qs, es);
    }
}
